package com.mk.shardingjdbcdemo.service.impl;

import com.mk.shardingjdbcdemo.dao.OrderDao;
import com.mk.shardingjdbcdemo.dao.OrderItemDao;
import com.mk.shardingjdbcdemo.entity.Order;
import com.mk.shardingjdbcdemo.entity.OrderItem;
import com.mk.shardingjdbcdemo.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderItemServiceImpl implements OrderItemService {

    @Autowired
    private OrderDao orderDao;
    @Autowired
    private OrderItemDao orderItemDao;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void save(Order order, OrderItem orderItem) {
        Order entityOrder = orderDao.save(order);
        orderItem.setOrderId(entityOrder.getOrderId());
        orderItemDao.save(orderItem);
    }
}
